package com.willian.andrappfw.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

public class WSwipeRefreshLayout extends SwipeRefreshLayout {
    final int touchSlop;
    private float downX;
    private float downY;

    public WSwipeRefreshLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    public WSwipeRefreshLayout(@NonNull Context context) {
        super(context);
        this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch(ev.getActionMasked()) {
            case 0:
                this.downX = ev.getX();
                this.downY = ev.getY();
                break;
            case 2:
                if (Math.abs(ev.getX() - this.downX) > (float)this.touchSlop) {
                    return false;
                }
        }

        return super.onInterceptTouchEvent(ev);
    }
}
